<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page import="org.tools.wstt.reference.ApplicationComponent"%>
<c:set var="title" scope="request">Proxy</c:set>

<jsp:include page="/WEB-INF/jsp/inc/head.jsp" />

		<h2>Forwarding Configuration</h2>
		<p>
			Set parameters for Proxy Forwarding.
		</p>
		<%
			request.setAttribute("host",application.getAttribute(ApplicationComponent.APP_CONFIG_PROXY_DEST_HOST));
			request.setAttribute("port",application.getAttribute(ApplicationComponent.APP_CONFIG_PROXY_DEST_PORT));
		%>
		<h3>Current configuration</h3> 
		<ul>
			<li>Host : <c:out value="${requestScope['host']}" /></li>
			<li>Port : <c:out value="${requestScope['port']}" /></li>
		</ul>
		
		<h3>Save a new configuration</h3>
		<form method="POST" action="<c:out value="${servicesPath}" /><%=ApplicationComponent.URI_PROXY_MANAGE %>">
			<p>
				<label for="destHost">Host : </label><input id="destHost" type="text" name="<%=ApplicationComponent.APP_CONFIG_PROXY_DEST_HOST %>" /><br />
				<label for="destPort">Port : </label><input id="destPort" type="text" name="<%=ApplicationComponent.APP_CONFIG_PROXY_DEST_PORT %>" /><br />
				<% if(System.getProperty("java.io.tmpdir") != null) { %>
				<input id="persistConf" type="checkbox" name="persistConf" /><label for="persistConf">Persist this configuration to a temporary file<strong>*</strong></label><br />
				<% } %>
				<input type="submit" value="Save Configuration" />
			</p>
			<% if(System.getProperty("java.io.tmpdir") != null) { %>
			<p>
				<em>* : be careful on multiple servers (clusters) on different physical machines or with different configured JVMs. The location of the persisted file may only be visible from the server having persisted the file.</em> 
			</p>
			<% } else { %>
			<p class="alert">
				<em>
					The current platform doesn't support saving to temporary files. So be careful, the configuration will be volatile between application or server restarts.
				</em>
			</p>
			<% } %>
		</form>
		
		<h2>Proxy Calls History</h2>
		<div id="proxy_streaming">
			<p><em>only the last <%=ApplicationComponent.APP_PROXY_REMIND_CALLS %> calls are viewable.</em></p>
			Since the last startup of the server, the proxy has treated <%=application.getAttribute(ApplicationComponent.APP_PROXY_CALLS_TOTAL_COUNT)%> requests for <%=application.getAttribute(ApplicationComponent.APP_PROXY_CALLS_TOTAL_TIME)%> ms elapsed.
			<table>
				<tbody>
					<tr>
						<th>Destination</th>
						<th>Call URI</th>
						<th>Date</th>
						<th>Time elapsed (ms)</th>
					</tr>
					<c:forEach var="call" items="${applicationScope['PROXY_CALLS']}">
						<tr>
							<td><c:out value="${call.destination}" /></td>
							<td><c:out value="${call.uri}" /></td>
							<td><fmt:formatDate pattern="dd/MM/yyyy HH:mm:SS" value="${call.date}" timeZone="GTM+1" /></td>
							<td><c:out value="${call.time}" /></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		
<jsp:include page="/WEB-INF/jsp/inc/foot.jsp" />
